import {productMethod} from '@/utils/models/product.js'
const crudMethod = new productMethod();
import Footer from '@/components/footer-main'
import { tableDicts} from "@/utils/common";

export default {
  name: 'Home',
  components: { Footer},
  data() {
    return {
      query: {
        productId: null
      },
      preview: null,
      loading: false,
      loadIntroduce: false,
      introduceData: [],
      curId: null,
      isShow: false,
      typeData: [
        { value: 1, label: '功能优势'},
        { value: 2, label: '应用场景'},
        { value: 3, label: '计费说明'}
      ],
    }
  },
  created() {
    this.query.productId = this.$route.query.id
    this.getDetails()
    this.getDetailIntroduce()
  },
  methods: {
    tableDicts,
    goDetails(link) {
      this.query.productId = link.productId
      this.getDetails()
      this.getDetailIntroduce()
    },
    handleMore() {
      this.isShow = !this.isShow
    },
    getDetails() {
      let _this = this
      _this.loading = true
      let params = {
        productId: _this.query.productId
      }
      crudMethod.getDetail(params).then((res) => {
        _this.loading = false
        let {msg, code, data} = res;
        document.title = data.data.productName
        data.data.productImg = data.data.productImg ? _this.baseURL + data.data.productImg : ''
        data.data.productRightImg = data.data.productRightImg ? data.data.productRightImg.split(',') : []
        _this.preview = data.data
      })
    },
    getDetailIntroduce() {
      let _this = this
      _this.loadIntroduce = true
      let params = {
        productId: _this.query.productId
      }
      crudMethod.getIntroduce(params).then((res) => {
        _this.loadIntroduce = false
        let {msg, code, data} = res;
        data.data.forEach(item => {
          item.introduceImg = item.introduceImg ? item.introduceImg.split(',') : []
        })
        for(let i in data.data) {
          let item = data.data[i]
          if(item.introduceType === 2) {
            _this.curId = item.introduceId
            break
          }
        }
        _this.introduceData = data.data
      })
    }
  }
}
